import { getStatistics, sellerRankings } from '../../service/api'

const state = {
    statistics : {},
    salesRanking : [],
}

const getters = {
    statistics : state => state.statistics,
    salesRanking : state => state.salesRanking,
}

const actions = {

    //销售统计
    async statistics ({state, commit}, para) {
        let res = await getStatistics(para.level_code, para.fx_level);
        if(res.errcode == 0){
            commit('setStatistics', res.data);
        }
    },


    //分销商销量排名
    async salesRanking ({state, commit}, para) {
        let res = await sellerRankings(para.level_code, para.fx_level, para.sale_code, para.attr_id);
        if(res.errcode == 0){
            commit('setSalesRanking', res.data);
        }
    },
}

const mutations = {

    setStatistics (state, value) {
        state.statistics = value;
    },
    setSalesRanking (state, value) {
        state.salesRanking = value;
    },
}

export default {
  state,
  getters,
  actions,
  mutations
}
